Page({

  /**
   * 页面的初始数据
   */
  data: {
    qualkey: 3,
    ishowtext: "show",
    textlimit: 0,
    skill: {
      name: "",
      intro: ""
    },
    state: "new",//默认新建，进来时带有状态时则变为修改。
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('crossdata', function (res) {
      that.setData({
        textlimit: res.data.intro.length,
        skill: res.data,
        state: "edit"
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  nameinput: function (e) {
    const that = this;
    that.data.skill.name = e.detail.value;
    that.setData({
      skill: that.data.skill,
    })
  },
  textarea: function (e) {
    const that = this;
    if (e.detail.value.length > 0) {
      that.setData({
        ishowtext: ""
      })
    } else {
      that.setData({
        ishowtext: "show"
      })
    }
    that.data.skill.intro = e.detail.value;
    that.setData({
      skill: that.data.skill,
      textlimit: e.detail.value.length
    })
  },
  back: function () {
    wx.navigateBack({})
  },
  commit: function () {
    const that = this;
    var box = that.data.skill;
    var title;
    if (box.name == "") {
      title = "请输入技能名称"
    } else if (box.intro == "") {
      title = "请填写该技能介绍"
    } else {
      if (that.data.state == "new") {
        box.resumeId = getApp().globalData.resumeId;
        getApp().globalData.post("/api/resume/certificate", box).then(res => {
          wx.navigateBack();
        })
      } else {
        getApp().globalData.post("/api/resume/certificate", box).then(res => {
          wx.navigateBack();
        })
      }
      return;
    }
    wx.showToast({
      title: title,
      icon: "none",
      duration: 1000
    })
  }
})